/*
 * @Author: candy
 * @Date:   2017-09-28 11:54:46
 * @Last Modified by:   candy
 * @Last Modified time: 2017-09-30 09:58:33
 */
require('./index.css');
var _mm = require("util/mm.js");
var _user = require('service/user-service.js');
var _cart=require('service/cart-service.js');
var nav = {
	init: function() {
		this.bindEvent();
		this.loadUs
		this.loadCartCount();
		return this;
	},
	bindEvent: function() {
		//登录
		$('.login').click(function() {
			_mm.loginIn();
		});
		//注册
		$('.regist').click(function() {
			window.location.href = "./regist.html"
		});
		//退出
		$('.logout').click(function() {
			_user.logout().done(function(res) {
				console.log('success');
			}).fail(function(errMsg) {
				console.log('失败');
			});
		});
	},
	//加载用户信息
	loadUserInfo: function() {
		_user.checkLogin().done(function(res) {
			console.log(res);
		}).fail(function(errMsg) {

		});
	},
	loadCartCount: function() {
		_cart.getCartCount().done(function(res) {
			$('#cartNum').text(res.data || 0);
			console.log(res);
		}).fail(function(errMsg) {
			$('#cartNum').text(0);
			console.log('失败');
		});
	}
}
module.exports = nav.init();